﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DataCenter.Model.Interface;
using DataCenter.Model.Model;
using Common.Util;

namespace DataCenter.Provider
{
    public class MessageHistoryProvider : GenericProvider, IMessageHistoryProvider
    {
        public bool Add(MessageHistory msg)
        {
            try
            {
                decimal maxval = 0;
                if (repository.MessageHistory.Any(x => x.MtSeq > 0))
                {
                    maxval = repository.MessageHistory.Max(x => x.MtSeq); 
                }
                msg.MtSeq = maxval + 1;

                repository.Add<MessageHistory>(msg);
                repository.UnitOfWork.SaveChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
